#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>
#include <unistd.h>
#include <string.h>
#include "support.h"
#include "toolbar.h"
#include "newinfo.h"
#include "addgroup.h"
#include "find.h"
#include "clist.h"
#include "message.h"
#include "mainwindow.h"
#include "file.h"

/*
 * this six callback functions for tool bar to handle clicked signal
 */

void on_button_new_info_clicked(GtkButton *button,gpointer user_data)
{
	handle_for_create_new_info(user_data);
}


void on_button_new_group_clicked(GtkButton *button,gpointer user_data)
{
	handle_for_create_window_add(user_data);
}


void on_button_save_clicked(GtkButton *button, gpointer user_data)
{
	struct file_ctrl *global_file=(struct file_ctrl *)user_data;
	if(global_file->data_mod) {
		save_all_file(global_file);
		global_file->data_mod=FALSE;
	}
}


void on_button_open_blog_clicked(GtkButton *button,gpointer user_data)
{
	struct clist_struct *clist=(struct clist_struct *)user_data;
	#ifdef _DEBUG_
		g_print("on_button_open_blog_clicked :------\n");
	#endif
	if(clist->show_all_row>0 && clist->show_selected_row != -1) {
		//g_print("on_button_open_blog_clicked :has go if\n");
		gchar *link;
		gtk_clist_get_text(GTK_CLIST(clist->clist_show),
				clist->show_selected_row,4,&link);
		if(strlen(link)==0||strcmp(link,"---")==0) {
			gchar msg[]="选中的信息博客记录为空!";
			message_box_for_toolbar(window_main,msg);
			return;
		}
		gchar blog[100];
		g_snprintf(blog,100,"firefox %s & >/dev/null",link);
		system(blog);
	}
}

void on_button_find_info_clicked(GtkButton *button,gpointer user_data)
{
	handle_for_create_window_find(user_data);
}

